<?php

namespace App\Controller\Api\User;

use App\Controller\Api\BaseController;
use App\Model\ConsultantDatum;
use App\Model\UserShortcut;
use App\Service\TalkService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Psr\Http\Message\ResponseInterface;

/**
 * @Controller(prefix="/user/v1/talk")
 */
class TalkController extends BaseController
{


    /**
     * @Inject()
     * @var TalkService
     */
    public $talkService;


    /**
     * @RequestMapping(path="getToken")
     * @return ResponseInterface
     */
    public function getToken()
    {



        $tokenInfo = $this->talkService->getEasemobToken($this->uid());
        if (is_array($tokenInfo)) {

            //延迟处理用户状态 暂时处理20秒之后更新用户状态
//            $this->jobService->SyncUserOnlineStatus($this->uid(),20);

            return $this->response->returnSuccess($tokenInfo);
        } else {
            return $this->response->returnFail();
        }

    }


    /**
     * 用户话术
     * @RequestMapping(path="userShortcutList")
     * @return ResponseInterface
     */
    public function userShortcutList()
    {

        // todo ---缓存
        $lang = getLang();
        $list = UserShortcut::where(['lang' => $lang])->orderByDesc('sort')->get()->toArray();
        return $this->response->returnSuccess(['list' => $list]);

    }


    /**
     * 聊天页面咨询卡片信息
     * @return ResponseInterface
     */
    public function consultantChatInfo()
    {

        $id = $this->request->query('id');

        $info = ConsultantDatum::consultantBaseInfo($id);

        $data = null;
        if ($info) {
            $data = [
                'uid' => $info['uid'],
                'num' => $info['num'],
                'nickname' => $info['nickname'],
                'cover' => $info['cover'],
                'countryName' => $info['countryName'],
                'direction' => $info['direction'],
                'hours' => $info['hours'],
                'praise' => $info['praise'],
                'language' => $info['language'],
            ];
        }

        return $this->response->returnSuccess(['info' => $data]);


    }


}